package com.ruoyi.framework.config;

import com.google.code.kaptcha.text.impl.DefaultTextCreator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.security.SecureRandom;
import java.util.Random;

/**
 * 验证码文本生成器
 * 
 * @author ruoyi
 */
public class KaptchaTextCreator2 extends DefaultTextCreator
{
    private static final Logger log = LoggerFactory.getLogger(KaptchaTextCreator2.class);

    private static final String[] CNUMBERS = "0,1,2,3,4,5,6,7,8,9,10".split(",");

    private static final String SYMBOLS = "0123456789"; // 数字
    // private static final String SYMBOLS = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";  // 字符串
    private static final Random RANDOM = new SecureRandom();


    /**
     * 获取长度为 4 的随机数字
     */
    public static String getRandomCode() {
        // 如果需要6位，那 new char[6] 即可，其他位数同理可得
        char[] nonceChars = new char[4];

        for (int index = 0; index < nonceChars.length; ++index) {
            nonceChars[index] = SYMBOLS.charAt(RANDOM.nextInt(SYMBOLS.length()));
        }

        return new String(nonceChars);
    }

    static int i = 0;

    @Override
    public String getText()
    {
//        Integer result = 0;
//        Random random = new Random();
//        int x = random.nextInt(10);
//        int y = random.nextInt(10);
//        StringBuilder suChinese = new StringBuilder();
//       suChinese.append(getRandomCode());
//        String res = suChinese.toString();
//        log.info(i++ + "登录的验证码为: " + res);
//        return res;

        return "1";
    }
}